﻿// See https://aka.ms/new-console-template for more information
class Matrix
{
    static void Main(string[] args)
    {
        Console.WriteLine("请输入数组行数n，列数m");
        string s = Console.ReadLine();
        string[] sarr = s.Split(' ');
        int n = int.Parse(sarr[0]);
        int m = int.Parse(sarr[1]);
        Matrix matrix = new Matrix();
        int [,] arr=matrix.createMatrix(n,m);
        //int[,] arr = { { 1, 2, 3 ,4}, { 5, 1, 2,3 }, { 9, 5,1, 2 } };
        bool b=matrix.isToeplitz(arr);
        if (b)
        {
            System.Console.WriteLine("该数组是托普利茨数组");
        }
        else
            System.Console.WriteLine("该数组不是托普利茨数组");
    }
    int[,] createMatrix(int n,int m)
    {
        int[,] arr = new int[n,m];
       
        Console.WriteLine("请输入n*m个数");
        string s = Console.ReadLine();
        string[] sArray = s.Split(' ');
        //Console.WriteLine(sArray.Length);
        for (int row = 0; row < n; row++)
        {
            for(int col = 0; col < m; col++)
            {
                int input = int.Parse(sArray[row*m+col]);
                
                //Console.WriteLine(input);
                arr[row,col] = input;
            }
        }
        return arr;
    }
    bool isToeplitz (int[,] arr)
    {
        for( int row = 0; row < arr.GetLength(0)-1; row++)
        {
            for(int col = 0;col < arr.GetLength(1)-1; col++)
            {
                if (arr[row + 1, col + 1] != arr[row,col])
                    return false;
            }
        }
        return true;
    }
}
